<?php
namespace app\common\validate;
use think\Validate;
use think\Request;
class MemberFans extends Validate{
     protected $rule =   [
        'userid' => 'number',
        'touserid' => 'number',
    ];
    protected $message  =   [
        'userid.number' => '用户id为数字',
        'touserid.number' => '用户id为数字',
    ];
    protected $scene = [
        'check_userid' => ['userid' => 'checkUserid'],
        'check_type' => ['touserid' => 'checkTouserid'],
    ];
    protected function checkUserid($value, $rule=[], $data){
    	$status = model("MemberFans")->where('userid', $value)->where('touserid', $data['touserid'])->value('status');
    	if ($status === 0) {
			return 2;
		}elseif ($status === 1) {
			return 1;
		}
		$result = model("MemberFans")->where('userid', $data['touserid'])->where('touserid', $value)->value('status');
		if ($result === 0) {
			return 3;
		}
		return false;
    }
    protected function checkTouserid($value, $rule=[], $data){
        $userid = $data['userid'];
        $touserid = $value;
        $count = model("MemberFans")->where('status', 1)->where("userid = '$userid' And touserid = '$touserid'")->whereOr("userid = '$touserid' And touserid = '$userid'")->count();
        if (!$count) {
            return '你们已经不是好友关系';
        }else{
            return true;
        }
    }
}